
<div class="box box-solid">
    <div class="box-body table-responsive no-padding" id="silder"> 
            <div class="box-body category_ul_area">
                <input type='hidden' name="<?php echo $this->name ?>" value='<?php echo $this->value; ?>' id="category_id_input" />
                <div class="form-group">
                    <label>顶级分类</label>
                    <select class="form-control required" name="" >
                        <?php if(!empty($category)): ?>
                            <option data-id="0">--请选择--</option>
                            <?php foreach ($category as $key => $value) :?>
                                <option data-id='<?php echo $value['sid'] ?>' ><?php echo $value['name'] ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                    <p class="help-blockk"></p>
                </div>
                
            </div> 
    </div>
</div>
<script type="text/javascript"> 
$(function(){
    $('.category_ul_area ').on('change','select',function(){
        var id = $(this).find('option:selected').data('id');
        var name = $(this).val(); 
        var dom = $(this);
        if (id != 0) {
            $('#category_id_input').val(id);
        }
        getSon(id,dom,name);
    })
});
function getSon(pid,dom,name){
    $.ajax({
        type:"get",
        dataType: "json",
        url: "<?php echo $this->getController()->createUrl('/category/getson')?>",
        data:{'sid':pid},
        success: function(json){ 
                var index = $(dom).parent().nextAll().remove();
            if (json != '' && json != 0) {
                var txt = '<div class="form-group">'+
                    '<label>'+name+'</label>'+
                    '<select class="form-control required" name="" >'+
                    '<option data-id="-1">--请选择--</option>';
                    $(json).each(function(i){
                        txt+='<option data-id="'+json[i]['id']+'">'+json[i]['name']+'</option>';
                    })
                    txt+='</select>'+
                    '<p class="help-blockk"></p>'+
                '</div>';
                $(dom).parent().parent().append(txt);
            }
        },
        error:function(e){

        }
    });
} 
</script>